// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.network.packets.hit;

import java.nio.ByteBuffer;
import zombie.characters.IsoGameCharacter;
import zombie.core.network.ByteBufferWriter;
import zombie.core.raknet.UdpConnection;
import zombie.inventory.types.HandWeapon;
import zombie.network.GameServer;
import zombie.network.packets.INetworkPacket;
import zombie.vehicles.BaseVehicle;
import zombie.vehicles.VehicleManager;

public class Vehicle extends Instance implements IPositional, INetworkPacket {
    protected BaseVehicle vehicle;

    public void set(BaseVehicle _vehicle) {
        super.set(_vehicle.getId());
        this.vehicle = _vehicle;
    }

    @Override
    public void parse(ByteBuffer b, UdpConnection connection) {
        super.parse(b, connection);
        this.vehicle = VehicleManager.instance.getVehicleByID(this.ID);
    }

    @Override
    public void write(ByteBufferWriter b) {
        super.write(b);
    }

    @Override
    public boolean isConsistent() {
        return super.isConsistent() && this.vehicle != null;
    }

    @Override
    public String getDescription() {
        return super.getDescription() + "\n\tVehicle [ vehicle=" + (this.vehicle == null ? "?" : "\"" + this.vehicle.getScriptName() + "\"") + " ]";
    }

    void process(IsoGameCharacter isoGameCharacter, HandWeapon handWeapon) {
        if (GameServer.bServer) {
            this.vehicle.hitVehicle(isoGameCharacter, handWeapon);
        }
    }

    BaseVehicle getVehicle() {
        return this.vehicle;
    }

    @Override
    public float getX() {
        return this.vehicle.getX();
    }

    @Override
    public float getY() {
        return this.vehicle.getY();
    }
}
